package com.burgeon.backend.Rest.Tool;
/**
 * 获取卡类型数量
 */


import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.json.JSONException;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class GetVIPTypeCount extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public GetVIPTypeCount(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     *
     * @return
     */

    public ArrayList getData() {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        ArrayList data = new ArrayList();
        JSONArray jsonArray = null;

        try {
            String str = RESULT(Data(), url);

            jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
            for (int i = 0; i < jsonArray.length(); i++) {
                HashMap map = new HashMap();
                map.put("name", jsonArray.getJSONArray(i).getString(0));
                map.put("value", jsonArray.getJSONArray(i).getString(1));
                data.add(map);
            }

        } catch (Exception e) {
            System.err.println("获取viptype视图数据错误");
        }

        return data;
    }

    private MultiValueMap Data() {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("VIP_TYPE");
        columns.add("QTY");

        params.put("columns", columns);
        params.put("table", "VIP_TYPE_CLASSIFICATION");//表名

        HashMap orderby = new HashMap();
        orderby.put("column", "QTY");
        orderby.put("asc", "false");
        ArrayList list = new ArrayList();
        list.add(orderby);

        params.put("orderby", list);


        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        GetVIPTypeCount g = new GetVIPTypeCount("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
